home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / gblanker3.5.src.lha / GSource / Blankers / ASwarm / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-04  |  4.2 KB  |  215 lines

  1. #include <libraries/gadtools.h>
  2.  
  3. #include <clib/exec_protos.h>
  4. #include <clib/intuition_protos.h>
  5. #include <clib/gadtools_protos.h>
  6.  
  7. #include "/Garshnelib/Garshnelib_protos.h"
  8. #include "/Garshnelib/Garshnelib_pragmas.h"
  9.  
  10. #include "ASwarm.h"
  11. #include "ASwarm_rev.h"
  12. #include "/main.h"
  13. #include "//defs.h"
  14.  
  15. #define MAX_SPEED 6L
  16. #define MAX_WASPS 10L
  17. #define MAX_BEES 500L
  18.  
  19. struct ModulePrefs {
  20.     LONG Mode;
  21.     LONG Wasps;
  22.     LONG Bees;
  23.     LONG WaspAcc;
  24.     LONG BeeAcc;
  25.     LONG Speed;
  26.     LONG Cycling;
  27.     LONG Aimmode;
  28. };
  29.  
  30. struct ModulePrefs nP;
  31. VOID *OldPrefs = 0L;
  32. STATIC const UBYTE VersTag[] = VERSTAG;
  33.  
  34. int BT_SAVEClicked( VOID )
  35. {
  36.     if( OldPrefs )
  37.     {
  38.         CopyMem( &nP, OldPrefs, sizeof( struct ModulePrefs ));
  39.         SavePrefs( OldPrefs );
  40.         OldPrefs = 0L;
  41.     }
  42.     
  43.     return QUIT;
  44. }
  45.  
  46. int BT_TESTClicked( VOID )
  47. {
  48.     MessageServer( BM_SENDBLANK );
  49.  
  50.     return OK;
  51. }
  52.  
  53. int BT_SCREENClicked( VOID )
  54. {
  55.     ScreenModeRequest( ASwarmWnd, &nP.Mode, 0L );
  56.     
  57.     return OK;
  58. }
  59.  
  60. int BT_CANCELClicked( VOID )
  61. {
  62.     OldPrefs = 0L;
  63.     
  64.     return QUIT;
  65. }
  66.  
  67. int CY_SPEEDClicked( VOID )
  68. {
  69.     nP.Speed = ASwarmMsg.Code;
  70.  
  71.     return OK;
  72. }
  73.  
  74. int SL_WASPSClicked( VOID )
  75. {
  76.     nP.Wasps = ASwarmMsg.Code;
  77.  
  78.     return OK;
  79. }
  80.  
  81. int SL_BEESClicked( VOID )
  82. {
  83.     nP.Bees = ASwarmMsg.Code * 10;
  84.  
  85.     return OK;
  86. }
  87.  
  88. int SL_WASPACCClicked( VOID )
  89. {
  90.     nP.WaspAcc = ASwarmMsg.Code;
  91.  
  92.     return OK;
  93. }
  94.  
  95. int SL_BEEACCClicked( VOID )
  96. {
  97.     nP.BeeAcc = ASwarmMsg.Code;
  98.  
  99.     return OK;
  100. }
  101.  
  102. int CY_CYCLEClicked( VOID )
  103. {
  104.     nP.Cycling = ASwarmMsg.Code;
  105.  
  106.     return OK;
  107. }
  108.  
  109. int CY_AIMClicked( VOID )
  110. {
  111.     nP.Aimmode = ASwarmMsg.Code;
  112.  
  113.     return OK;
  114. }
  115.  
  116. #define BL_SetGadgetAttrs( Gad, Tag, Val ) GT_SetGadgetAttrs( ASwarmGadgets[Gad], ASwarmWnd, 0L, Tag, Val, TAG_END )
  117.  
  118. int ASwarmVanillaKey( VOID )
  119. {
  120.     switch( ASwarmMsg.Code ) {
  121.     case 's':
  122.         return BT_SAVEClicked();
  123.     case 't':
  124.         return BT_TESTClicked();
  125.     case 'd':
  126.         return BT_SCREENClicked();
  127.     case 'c':
  128.         return QUIT;
  129.     case 'w':
  130.         BL_SetGadgetAttrs( GD_SL_WASPS, GTSL_Level, Inc( nP.Wasps, 1, MAX_WASPS ));
  131.         return OK;
  132.     case 'W':
  133.         BL_SetGadgetAttrs( GD_SL_WASPS, GTSL_Level, Dec( nP.Wasps, 1, 1 ));
  134.         return OK;
  135.     case 'b':
  136.         BL_SetGadgetAttrs( GD_SL_BEES, GTSL_Level, Inc( nP.Bees, 10, MAX_BEES ));
  137.         return OK;
  138.     case 'B':
  139.         BL_SetGadgetAttrs( GD_SL_BEES, GTSL_Level, Dec( nP.Bees, 10, 10 ));
  140.         return OK;
  141.     case 'l':
  142.         BL_SetGadgetAttrs( GD_SL_WASPACC, GTSL_Level, Inc( nP.WaspAcc, 1, 15 ));
  143.         return OK;
  144.     case 'L':
  145.         BL_SetGadgetAttrs( GD_SL_WASPACC, GTSL_Level, Dec( nP.WaspAcc, 1, 1 ));
  146.         return OK;
  147.     case 'e':
  148.         BL_SetGadgetAttrs( GD_SL_BEEACC, GTSL_Level, Inc( nP.BeeAcc, 1, 15 ));
  149.         return OK;
  150.     case 'E':
  151.         BL_SetGadgetAttrs( GD_SL_BEEACC, GTSL_Level, Dec( nP.BeeAcc, 1, 1 ));
  152.         return OK;
  153.     case 'o':
  154.         BL_SetGadgetAttrs( GD_CY_CYCLE, GTCY_Active, nP.Cycling = 1-nP.Cycling );
  155.         return OK;
  156.     case 'p':
  157.         BL_SetGadgetAttrs( GD_CY_SPEED, GTCY_Active, Inc( nP.Speed, 1, MAX_SPEED ));
  158.         return OK;
  159.     case 'P':
  160.         BL_SetGadgetAttrs( GD_CY_SPEED, GTCY_Active, Dec( nP.Speed, 1, 0 ));
  161.         return OK;
  162.     case 'a':
  163.         BL_SetGadgetAttrs( GD_CY_AIM, GTCY_Active, nP.Aimmode = 1-nP.Aimmode );
  164.     default:
  165.         return OK;
  166.     }
  167. }
  168.  
  169. VOID DoPrefs( LONG command, VOID *Prefs )
  170. {
  171.     switch( command )
  172.     {
  173.     case STARTUP:
  174.         OldPrefs = Prefs;
  175.         CopyMem( Prefs, &nP, sizeof( struct ModulePrefs ));
  176.         if( !SetupScreen())
  177.         {
  178.             ASwarmLeft = ( Scr->Width - ComputeX( ASwarmWidth ))/2 - Scr->WBorRight;
  179.             ASwarmTop = ( Scr->Height - ComputeY( ASwarmHeight ) - Font->ta_YSize )/2 -
  180.                 Scr->WBorBottom;
  181.             if( !OpenASwarmWindow())
  182.             {
  183.                 BL_SetGadgetAttrs( GD_SL_WASPS, GTSL_Level, nP.Wasps );
  184.                 BL_SetGadgetAttrs( GD_SL_BEES, GTSL_Level, nP.Bees/10 );
  185.                 BL_SetGadgetAttrs( GD_SL_WASPACC, GTSL_Level, nP.WaspAcc );
  186.                 BL_SetGadgetAttrs( GD_SL_BEEACC, GTSL_Level, nP.BeeAcc );
  187.                 BL_SetGadgetAttrs( GD_CY_SPEED, GTCY_Active, nP.Speed );
  188.                 BL_SetGadgetAttrs( GD_CY_CYCLE, GTCY_Active, nP.Cycling );
  189.                 BL_SetGadgetAttrs( GD_CY_AIM, GTCY_Active, nP.Aimmode );
  190.             }
  191.             CloseDownScreen();
  192.         }
  193.         break;
  194.     case IDCMP:
  195.         if( HandleASwarmIDCMP() != QUIT )
  196.             break;
  197.     case KILL:
  198.         CloseASwarmWindow();
  199.         break;
  200.     }
  201. }
  202.  
  203. LONG WndSignal( VOID )
  204. {
  205.     return ASwarmWnd ? 1L << ASwarmWnd->UserPort->mp_SigBit : 0L;
  206. }
  207.  
  208. VOID FillDefaults( VOID *Prefs )
  209. {
  210.     struct ModulePrefs mPO = { 0L, 3L, 16L, 3L, 4L, 5L, 0L, 0L };
  211.  
  212.     mPO.Mode = getTopScreenMode();
  213.     CopyMem( &mPO, Prefs, sizeof( struct ModulePrefs ));
  214. }
  215.